#!/usr/bin/env python
#
# Copyright 2008 Allen Hutchison (allen@hutchison.org)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# $URL: http://severedelays.googlecode.com/svn/trunk/appengine-tests/test/store_status_test.py $
__version__ = "$Rev: 31 $"
__author__ = "Allen Hutchison (allen@hutchison.org)"

"""Unit tests for StoreStatus"""

import datetime
import unittest

from lib.store_status import StoreStatus

from google.appengine.api import memcache

class StoreStatusTest(unittest.TestCase):
  def setUp(self):
    memcache.flush_all()
  
  def test_initNoMemcache(self):
    memcache.flush_all()
    s = StoreStatus(prefix='TEST', minutes=0.05)
    self.assertEquals(s.prefix, 'TEST', 'Expected prefix to be TEST.')
    self.assertEquals(s.elapsedTime, datetime.timedelta(0, 3, 0), 
                      'Elapsed time should be 3')
    self.assertTrue(s.update, 'Update should be true.')
    self.assertEquals(s.data, [], 'Data should be empty list.')
    self.assertTrue(s.tflP is not None, 'tflP should have something in it.')
  
  def test_initWithMemcache(self):
    memcache.flush_all()
    memcache.set('TEST-TIME', datetime.datetime.now())
    s = StoreStatus(prefix='TEST')
    self.assertFalse(s.update, 'Update should be false.')
    self.assertEquals(memcache.get('TEST-DATA'), None, 
                      'Test data should be empty.')
      